package simbot.example.xxjob;

import lombok.Data;
import love.forte.common.utils.Carrier;
import love.forte.simbot.api.message.assists.Flag;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.message.events.PrivateMsg;
import love.forte.simbot.api.sender.BotSender;
import love.forte.simbot.bot.BotManager;
import love.forte.simbot.component.mirai.additional.MiraiAdditionalApis;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import love.forte.simbot.api.sender.Sender;
import simbot.example.entity.Information;
import simbot.example.listener.MyGroupListen;
import simbot.example.mapper.InformationMapper;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName: TimedTask
 * @Author: CYC
 * @Date: 2021/10/27
 */
@Data
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class TimedTask {

    @Resource
    private MyGroupListen myGroupListen;

    @Resource
    private InformationMapper informationMapper;


//    public static String[] sentences2 ={"你怎么睡得着的！你这个年龄段你这个阶段你睡得着觉！有点出息没有？！","你那个态度已经让我看不下去了","大学不是这么读的啊"};

    private int state = 1;

    //3.添加定时任务
    @Scheduled(cron = "0/5 * * * * ?")
    //或直接指定时间间隔，例如：5秒
    private void configureTasks() {

        Information information = informationMapper.selectById(1);
        if (information.getSatiety().compareTo(new BigDecimal(0)) == 1) {
            information.setNoFood(0);
            information.setSatiety(information.getSatiety().subtract(new BigDecimal("0.02")));
            if (information.getSatiety().compareTo(new BigDecimal(100)) == 1){
                information.setAccumulate(information.getAccumulate().add(new BigDecimal("0.02")));
                if (information.getAccumulate().compareTo(new BigDecimal("1.00"))==0){
                    information.setWeight(information.getWeight().add(new BigDecimal("0.01")));
                    information.setAccumulate(new BigDecimal("0.00"));
                }
            }
            informationMapper.updateById(information);
        }else {
            if (information.getWeight().compareTo(new BigDecimal("40.00")) == 1&&information.getNoFood()%1800==0){
                information.setWeight(information.getWeight().subtract(new BigDecimal("0.01")));
            }
            information.setNoFood(information.getNoFood()+5);
            informationMapper.updateById(information);
        }

        myGroupListen.task(state);

    }


}
